from Response_health_advice.Advice_Data import TONGUE_BODY_MAP, COATING_COLOR_MAP, HERBAL_LIB, DIET_LIB, LIFESTYLE_LIB


def analyze_tongue_features(tongue_color: str, coating_color: str, coating_texture: str):
    """
    返回值：证候列表（可能多个）
    """
    body_condition = TONGUE_BODY_MAP.get(tongue_color, '未识别的舌质颜色')
    coating_dict   = COATING_COLOR_MAP.get(coating_color, {})
    coating_condition = coating_dict.get(coating_texture, '未识别的舌苔颜色或质地')
    return body_condition, coating_condition


def recommend_treatment(body_condition: str, coating_condition: str):
    """
    返回值：结构化调理方案
    """
    # 把舌苔证候拆成关键字，便于匹配
    keywords = set()
    for word in ['气血两虚', '阳虚', '实热', '虚热', '湿热', '痰湿', '血瘀', '寒湿']:
        if word in body_condition or word in coating_condition:
            keywords.add(word)

    # 如果都没有命中，给一个兜底
    if not keywords:
        keywords = {'通用'}

    treatment_plan = {
        '中药调理': {k: HERBAL_LIB.get(k, '请面诊中医') for k in keywords},
        '食疗推荐': {k: DIET_LIB.get(k, ['均衡饮食即可']) for k in keywords},
        '生活习惯': {k: LIFESTYLE_LIB.get(k, ['保持规律作息', '心情舒畅']) for k in keywords}
    }
    return treatment_plan

if __name__ == '__main__':
    body, coat = analyze_tongue_features('红舌', '黄苔', '腻苔')
    print('证候:', body, coat)
    print('方案:', recommend_treatment(body, coat))